package sleep;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ThreadSleepDemo {

    public static void countDown(long mills) {
        Date endDate = new Date(System.currentTimeMillis() + mills);
        long endTime = endDate.getTime();

        while (true) {
            System.out.println(new SimpleDateFormat("hh:mm:ss").format(endDate));
            //下一秒时间
            endDate = new Date(endDate.getTime() - 1000);
            //休眠一秒钟
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (endTime - endDate.getTime() > mills) {
                break;
            }
        }
    }



    public static void main(String[] args) throws InterruptedException {

        ThreadSleepDemo.countDown(10000); ////倒计时10秒
    }
}
